package com.vina.web.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.TemplateMode;
import org.thymeleaf.context.WebContext;

import com.vina.web.thymeleaf.TemplateEngineUtil;

public class VinapageServlet extends HttpServlet  {

	private static final long serialVersionUID = 5000397819223446232L;
	private static TemplateEngine te;
//	private static String encoding;
	
	public VinapageServlet(){
		super();
		te = TemplateEngineUtil.getInstance().getEngine();
	}
	
	@Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doService(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doService(request, response);
    }

    protected void doService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        response.setCharacterEncoding(encoding);

        WebContext ctx = new WebContext(request, getServletContext(), request.getLocale());
//        String templateName = TemplateEngineUtil.getInstance().getTemplateName(request);
//        ctx.setVariable("today", Calendar.getInstance());
        te.process("home", ctx, response.getWriter());

    }

}
